package com.example.springboot.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

@Data
public class PostVo {
    @JsonProperty("id")
    private Integer id;
    @JsonProperty("content")
    private String content;
    @JsonProperty("author_id")
    private Integer authorId;
    @JsonProperty("category_id")
    private Integer categoryId;
    @JsonProperty("tokens")
    private String tokens;
    @JsonProperty("tags")
    private String tags;
    @JsonProperty("updated_time")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp updatedTime;
    @JsonProperty("published_time")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp publishedTime;
    @JsonProperty("status")
    private Integer status;
    @JsonProperty("views")
    private Integer views;
    @JsonProperty("likes")
    private Integer likes;
    @JsonProperty("comments_count")
    private Integer commentsCount;
    @JsonProperty("collect_count")
    private Integer collectCount;
    @JsonProperty("article_type")
    private Integer articleType;
    @JsonProperty("cover")
    private String cover;
    @JsonProperty("title")
    private String title;
    @JsonProperty("summary")
    private String summary;
    @JsonProperty("nickname")
    private String nickname;


    @JsonIgnore
    public String getFormattedPublishedTime() {
        if (publishedTime != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(publishedTime);
        }
        return null;
    }
}